package springinpractice.common.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

@Aspect
public class ForkAspect {
	private static final Logger log = Logger.getLogger(ForkAspect.class);
	
	@Pointcut("execution(* org.springframework.mail.javamail.JavaMailSenderImpl.send(..))")
	public void send() { }
	
	@Around("send()")
	public void fork(final ProceedingJoinPoint pjp) {
		new Thread(new Runnable() {
			public void run() {
				try {
					pjp.proceed();
				} catch (Throwable t) {
					// All we can do is log an exception
					log.error(t);
				}
			}
		}).start();
	}
}
